function checkPhone(val) {
  //手机号正则验证
  let reg = /^1[3456789]{1}\d{9}$/;
  if (val == "") {
    return "手机号不能为空";
  } else if (reg.test(val)) {
    return "";
  } else {
    return "手机号格式不正确";
  }
}

function checkIdCard(id) {
  const regex =
    /^[1-9]\d{5}(18|19|20|21|22)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|[Xx])$/;
  if (id == "") {
    return "身份证号码不能为空";
  } else if (regex.test(id)) {
    return "";
  } else {
    return "请输入正确的身份证号码";
  }
}
function validateAmount(input) {
  if (!input) {
    return { valid: false, message: "金额不能为空" };
  }

  const amountRegex = /^(?!0+(?:\.0+)?$)\d+(?:\.\d{1,2})?$/;

  if (!amountRegex.test(input)) {
    if (/^0+(?:\.0+)?$/.test(input)) {
      return { valid: false, message: "金额必须大于0" };
    }
    if (/,/.test(input)) {
      return { valid: false, message: "金额不能包含逗号" };
    }
    if (!/^\d+(?:\.\d{1,2})?$/.test(input)) {
      return { valid: false, message: "金额最多保留2位小数" };
    }
    return { valid: false, message: "金额格式不正确" };
  }
  return { valid: true, message: "金额有效" };
}
function isPositiveInteger(value) {
  return /^[1-9]\d*$/.test(value);
}
export default {
  checkPhone,
  checkIdCard,
  validateAmount,
  isPositiveInteger,
};
